package com.zym.init.enums;

import lombok.Getter;
import org.springframework.util.StringUtils;

/**
 * 存储服务商枚举
 *
 * @author ZouYangMing
 */
@Getter
public enum StorageServiceProviderEnum {
    /**
     * 本地
     */
    LOCAL("local"),
    MINIO("minio");

    private final String serviceProvider;

    StorageServiceProviderEnum(String serviceProvider) {
        this.serviceProvider = serviceProvider;
    }

    /**
     * 根据 serviceProvider 获取枚举
     *
     * @param serviceProvider 服务商
     * @return 枚举
     */
    public static StorageServiceProviderEnum getEnumByServiceProvider(String serviceProvider) {
        if (!StringUtils.hasLength(serviceProvider)) {
            return null;
        }
        for (StorageServiceProviderEnum anEnum : StorageServiceProviderEnum.values()) {
            if (anEnum.serviceProvider.equals(serviceProvider)) {
                return anEnum;
            }
        }
        return null;
    }

    /**
     * 校验范围
     *
     * @param serviceProvider 服务商
     * @return 结果
     */
    public static boolean isValidCode(String serviceProvider) {
        if (serviceProvider == null) {
            return false;
        }
        for (StorageServiceProviderEnum s : StorageServiceProviderEnum.values()) {
            if (s.getServiceProvider().equals(serviceProvider)) {
                return true;
            }
        }
        return false;
    }

}
